﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using UtilityLibrary;

namespace MapLibrary.Events
{
    /// <summary>
    /// An event that triggers when the user is past a certain x position in the world.
    /// </summary>
    public class OneShotTextEvent : OneShotEvent
    {

        private string toDisplay;
        private int displayFrames;
        private int displayCount;
        private float xThreshold;

        public OneShotTextEvent(GameWorld world, string toDisplay, int displayFrames, float xThreshold) : base(world)
        {
            this.toDisplay = toDisplay;
            this.displayFrames = displayFrames;
            this.xThreshold = xThreshold;
            this.displayCount = 0;
        }

        public override void Update()
        {
            //don't do anything if triggered
            if(hasTriggered)
                return;

            if (world.CurrentLevel.Player.Body.Position.X > xThreshold)
            {
                Act();
            }
        }

        public override void Draw(Microsoft.Xna.Framework.Graphics.SpriteBatch batch)
        {
            displayCount++;

            if (displayCount < displayFrames)
            {
                PrimitiveBrush.RenderText(batch, toDisplay, new Microsoft.Xna.Framework.Vector2(20, 700));
            }
            else
                displayCount = displayFrames;   //ensure it stops growing
        }
    }
}
